package com.lecture.java8.mvel;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2021/4/1 8:59
 */
public class PatternTest {

    public static void main(String[] args){
        /*String content = "(abs(abs(99)) > 9 || current(\"tagname\", $time) > 10 && absr(abs(99)) < 10) ";

        //String pattern = "(abs\\(abs\\(\\d\\d\\)).+ (absr\\(abs\\(\\d\\d\\)).+ (current\\(\"\\w+\".+\\$\\w+\\))";
        String pattern = "(current\\(\"\\w+\".+\\$\\w+\\))";

        // 创建 Pattern 对象
        Pattern p = Pattern.compile(pattern);


        // 现在创建 matcher 对象
        Matcher m = p.matcher(content);

        while (m.find()) {
            System.out.println(m.group());
        }*/

        /*if (m.find()) {
            System.out.println("Found value: " + m.group(0) );
            System.out.println("Found value: " + m.group(1) );
            System.out.println("Found value: " + m.group(2) );
            System.out.println("Found value: " + m.group(3) );
        } else {
            System.out.println("NO MATCH");
        }*/

        String regex = "current([\\s\\S]*?)\\)|avg([\\s\\S]*?)\\)";

        Matcher matcher = Pattern.compile(regex).matcher("我们是为了获取所有以【解析】开头，以current(343)【结尾 的数据。我们current(3489)avg(3489)以【解析】开头，以【结尾 的数据。");

       /* if (matcher.find()){
            System.out.println(matcher.group(1).trim());
        }*/
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }
}
